<template>
  <div class="title"> 申购抽签 </div>
  <div class="Collection">
    <van-sticky>
      <van-row class="all-select">
        <van-col span="7" v-for="(item, index) in tabList" :key="index"
          :class="formData.tabActive == index ? 'tabactive fadenum' : ''" @click="getmenu(item.id, index, item.type)">
          <span>{{ item.name }}</span>

          <div v-if="item.name">
            <img src="@/assets/image/icon/last.png" alt="" class="upper">
            <img src="@/assets/image/icon/nexxt.png" alt="" class="lower">
          </div>
        </van-col>

        <!-- <van-col span="3">
          <div class="rank" @click="rangk()">
            <img src="@/assets/image/icon/menu-col.png" alt="" v-if="formData.rankShow">
            <img src="@/assets/image/icon/menu-row.png" alt="" v-else>
          </div>
        </van-col> -->
      </van-row>

      <van-row class="select-item" v-if="formData.seabhidden">
        <van-col v-for="(item, index) in selectlist" :key="index">
          <span
            :class="formData.itemActive == (item.collectionTypeId ? item.collectionTypeId : item.index) ? 'selectactive' : ''"
            @click="getmore(item.applyCollectionId ? item.collectionTypeId : item.index, index)">{{ item.name }}</span>
        </van-col>
      </van-row>
      <form action="/" v-else>
        <van-search v-model="formData.query" show-action placeholder="请输入搜索关键词" @search="onSearch" @cancel="onCancel">
          <template #left-icon>
            <img src="@/assets/image/icon/seach.png" alt="">
          </template>
        </van-search>
      </form>
    </van-sticky>
    <van-list v-model:loading="formData.loading" :finished="formData.finished" @load="onLoad" finished-text="我是有底线的~">
      <van-grid :column-num="formData.grid">

        <van-grid-item v-for="(item, index) in Contentlist" :key="index" :gutter="40">
          <div class="" :class="formData.grid == 1 ? 'widthwarp' : 'col-warp'">
            <div class="Content-product">
              <div class="img-box" :style="'background-image:url(' + item.image + ') '"
                @click="GoInner(item.applyCollectionId)">
                <div class="time-warp warp" v-if="item.registrationStatus == 2"> <img
                    src="@/assets/image/icon/time.png" /> 报名倒计时
                  <van-count-down :time="item.surplusTime" format="DD 天 HH 时 mm 分 ss 秒" style="display: inline-block;
    color: #8ec984" />
                </div>
                <div class="seld-warp warp" v-if="item.registrationStatus == 1"> <img
                    src="@/assets/image/icon/seld.png" />已结束</div>
                <div class="light-warp warp" v-if="item.registrationStatus == 0"> <img
                    src="@/assets/image/icon/lightning.png" />报名中</div>
              </div>
              <div class="cont" @click="GoInner(item.applyCollectionId)">
                <p>{{ item.name ? item.name : "活动 " }}</p>
                <div class="Limit-warp">
                  <span>报名</span>
                  <span>{{ item.applyUserCount ? item.applyUserCount : "0" }}人</span>
                  <div class="linercolor">￥ {{ item.price ? item.price : "0" }}</div>
                </div>

                <van-row class="flex-warp">
                  <van-col span="24" class='txt'>报名：{{ item.startTime }} 至 {{ item.endTime }}</van-col>
                  <van-col span="24" class='txt'>抽签时间：{{ item.endTime }}</van-col>
                </van-row>
              </div>
            </div>
          </div>
        </van-grid-item>

      </van-grid>
    </van-list>
  </div>

</template>
<script>
import { ref, defineComponent, reactive, onMounted, toRefs, nextTick } from "vue";
import { CollectionType, SellStatus, drawCollection } from "@/api/public";
import { formMonth, subTime, countTime, transformTimestamp } from "@/utils/phone";
import { useRouter } from "vue-router"
import { Toast } from "vant";
import { useStore } from "vuex";
export default defineComponent({
  props: {
    menulist: {
      type: Array
    }
  },
  setup(props) {
    console.log("props===", props);
    const store = useStore();
    const router = useRouter()
    const formData = reactive({
      pageNum: 1,
      pageSize: 2,
      total1: 0,
      finished: false,
      loading: true,
      seabhidden: false,
      rankShow: true,
      itemActive: null,
      tabActive: 0,
      grid: 1,
      keywords: "",
      isPrice: "",
      query: "",
      status: "",
      type: ""

    })
    const tabList = ref([])
    const selectlist1 = ref([])
    onMounted(() => {

      const type = localStorage.getItem('type')
      tabList.value = [
        { id: 1, name: "全部价格", type: 2 },
        { id: 2, name: "全部状态", type: 2 },
        {}
      ]
    })

    const onLoad = async (val) => {
      const res = await drawCollection(formData)
      formData.loading = false
      formData.pageNum++
      formData.total = res.data.data.total
      Contentlist.value = Contentlist.value.concat(res.data.data.records)
      if (formData.total <= Contentlist.value.length) {
        formData.finished = true;
        console.log('不加载')
      } else {
        formData.finished = false;
      }
      formData.loading = false
    }
    const GoInner = (id) => {
      router.push({
        path: '/applyDetails',
        query: {
          id: id
        }
      })
    }
    const Contentlist = ref([])
    const selectlist = ref([
      // { index: null, name: "全部价格" },
      { index: 0, name: "价格升序" },
      { index: 1, name: "价格倒序" },
    ])

    const onSearch = () => {
      formData.loading = true
      formData.finished = false
      Contentlist.value = []
      formData.pageNum = 1
      onLoad(1)
    }
    const onCancel = () => {

    }
    const parmas = ref({})
    const getmore = async (id, index) => {
      formData.loading = true
      formData.finished = false
      console.log(id, "id")
      Contentlist.value = []
      formData.itemActive = id
      formData.pageNum = 1
      if (formData.type == 1) {
        formData.isPrice = id
        formData.status = null
      } else {
        formData.status = id
        formData.isPrice = null
      }
      onLoad()
    }
    const rangk = () => {
      formData.seabhidden = false
      formData.rankShow = !formData.rankShow
      if (formData.rankShow) {
        formData.grid = 2
      } else {
        formData.grid = 1
      }
    }
    const getmenu = async (id, index, type) => {
      formData.pageNum = 1
      console.log(id, index, type)
      formData.seabhidden = !formData.seabhidden
      formData.tabActive = index
      formData.type = id
      if (id == 2) {
        SellStatus().then(res => {
          selectlist.value = [
            { index: null, name: "全部" },
            { index: 0, name: "报名中" },
            { index: 1, name: "已结束" },
            { index: 2, name: "未开启" }
          ]

        })
      } else if (id == 3) {
        const res = await CollectionType()
        selectlist.value = [
          { index: null, name: "报名中" },
          { index: 0, name: "已结束" },
          { index: 1, name: "未开启" },
        ]
      } else {
        selectlist.value = [
          { index: null, name: "全部价格" },
          { index: 0, name: "价格升序" },
          { index: 1, name: "价格倒序" },
        ]
      }
    }
    return {
      formData, selectlist, tabList, getmore, getmenu, rangk, Contentlist, onSearch, onCancel, GoInner, onLoad,
      subTime,
    }

  }

})
</script>
<style lang="less" scoped>
.title {
  padding: 10px 0px 0px;
  font-size: 36px;
  font-family: Source Han Sans CN;
  font-weight: bold;
  color: #ffffff;
  line-height: 76px;
  text-align: center;
}

.img-box {
  img {
    width: 27px;
    vertical-align: middle;
    margin-right: 5px;
  }

  .time-warp {
    color: #169900;
  }

  .seld-warp {
    color: #b9c4c7;
  }

  .light-warp {
    color: #eb0407;

    img {
      width: 17px;
      height: 24px;
    }
  }

  .warp {
    padding: 10px 20px;
    margin: 10px 12px 0px;
    background: #000000;
    border-radius: 26px;
    display: block;
    width: fit-content;
    align-items: center;
  }
}

&:deep(.van-search) {
  background: #202123;
}

&:deep(.van-field) {
  margin-bottom: 0px;
  background: transparent;
  height: auto;
}

&:deep(.van-search__action) {
  font-size: 30px;
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: #b9c4c7;
  line-height: 18px;
}

&:deep(.van-search__content--square) {
  width: 628px;
  height: 68px;
  background: #282a2c;
  border-radius: 34px;
  padding-left: 20px;

  img {
    width: 32px;
    height: 32px;
    line-height: 68px;
    margin-left: 10px;
    margin-top: 6px;
  }
}

&:deep(.van-sticky--fixed) {
  background: #282a2c;
  height: auto !important;
}

&:deep(.van-hairline--top) {
  margin: 0px 10px;
  //   background: #161718;
  //   width: 94%;
  //   margin: 30px auto;
  border: none;
}

&:deep(.van-hairline--top:after) {
  border-top-width: 0px;
}

&:deep(.van-grid-item__content) {
  padding: 30px 0px 0px;
  background: transparent;
}

&:deep(.van-hairline:after) {
  border: none;
}

&:deep(.van-grid-item) {
  background: transparent;
}

.col-warp {
  .Content-product {
    border-radius: 40px 40px 0px 0px;
    background: linear-gradient(to bottom, #4b4c4d, #161718);
    width: 344px;
    // height: 543px;
    background: #282a2c;
    border-radius: 40px;

    .cont {
      position: relative;
      padding: 15px 12px;

      p {
        height: 50px;
        font-size: 32px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        color: #ffffff;
        line-height: 50px;
      }

      .txt {
        font-size: 26px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        color: #b9c4c7;
        line-height: 48px;
      }

      .linercolor {
        right: 10px;
        top: 0px;
        position: absolute;
        text-align: right;
        font-size: 38px;
        font-family: Source Han Sans CN;
        font-weight: bold;
        color: #ffffff;
        line-height: 73px;

        background: linear-gradient(-90deg, #37dc6d 0%, #34d1f9 100%);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
      }

      .flex-warp {
        display: flex;
        align-items: center;
      }

      .Limit-warp {
        margin: 10px 0;

        span {
          font-size: 26px;
          font-family: Source Han Sans CN;
          font-weight: 400;
          line-height: 48px;
        }

        span:nth-child(1) {
          color: #444442;
          font-size: 26px;
          font-family: Source Han Sans CN;
          font-weight: 400;
          background: #f3e3bb;
          border-radius: 4px 0px 0px 4px;
          padding: 3px 12px;
        }

        span:nth-child(2) {
          padding: 3px 12px;
          background: #444442;
          border-radius: 4px;
          font-size: 26px;
          font-family: Source Han Sans CN;
          font-weight: 400;
          color: #f3e3bb;
          line-height: 48px;
        }
      }
    }

    .img-box {
      // padding-top: 20px;
      width: 334px;
      height: 334px;
      background-size: 100%;
      border-radius: 40px 40px 0px 0px;
      border: 2px solid #ffffff;
      background-repeat: no-repeat;
      background-position: center center;
      overflow: hidden;
    }
  }
}

.widthwarp {
  width: 708px !important;

  .Content-product {
    border-radius: 40px 40px 0px 0px;
    background: linear-gradient(to bottom, #4b4c4d, #161718);
    width: 708px !important;
    // height: 543px;
    background: #282a2c;
    border-radius: 40px;

    .cont {
      position: relative;
      padding: 30px 30px 30px 37px;

      p {
        font-size: 32px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        color: #ffffff;
      }

      .txt {
        font-size: 26px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        color: #b9c4c7;
        line-height: 48px;
      }

      .linercolor {
        right: 30px;
        top: 60px;
        position: absolute;
        text-align: right;
        font-size: 40px;
        font-family: Source Han Sans CN;
        font-weight: bold;
        color: #ffffff;
        line-height: 73px;

        background: linear-gradient(-90deg, #37dc6d 0%, #34d1f9 100%);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
      }

      .flex-warp {
        display: flex;
        align-items: center;
      }

      .Limit-warp {
        margin-top: 20px;

        span {
          font-size: 26px;
          font-family: Source Han Sans CN;
          font-weight: 400;
          line-height: 48px;
        }

        span:nth-child(1) {
          color: #444442;
          font-size: 26px;
          font-family: Source Han Sans CN;
          font-weight: 400;
          background: #f3e3bb;
          border-radius: 4px 0px 0px 4px;
          padding: 3px 12px;
        }

        span:nth-child(2) {
          padding: 3px 12px;
          background: #444442;
          border-radius: 4px;
          font-size: 26px;
          font-family: Source Han Sans CN;
          font-weight: 400;
          color: #f3e3bb;
          line-height: 48px;
        }
      }
    }

    .warp {
      margin-top: 20px;
      margin-left: 47px;
      padding: 14px 30px;
    }

    .img-box {
      // padding-top: 40px;
      width: 708px !important;
      height: 708px !important;
      background-size: 100%;
      border-radius: 40px 40px 0px 0px;
      border: 2px solid #ffffff;
      background-repeat: no-repeat;
      background-position: center center;
      overflow: hidden;
    }
  }
}

.all-select {
  margin-top: 30px;
  background: #282a2c;
  padding: 26px 21px;
  display: flex;

  &:deep(.van-col) {
    text-align: center;
    display: flex;
    justify-content: center;
    align-items: center;

    span {
      font-size: 30px;
      font-family: Source Han Sans CN;
      font-weight: 400;
      color: #ffffff;
      line-height: 30px;
    }

    img {
      width: 28px;
      height: 16px;
      margin-left: 10px;
    }
  }

  .rank {
    img {
      width: 48px;
      height: 48px;
    }
  }

  .upper {
    display: none;
    // transform: rotate(360deg);
    // transform: rotate(90deg);
  }

  .lower {
    display: block;
  }

  @keyframes masked-animation {
    0% {
      transform: rotate(0deg);
    }

    100% {
      transform: rotate(360deg);
    }
  }

  @keyframes opacity-animation {
    0% {
      opacity: 0;
    }

    100% {
      opacity: 1;
    }
  }

  .tabactive {
    span {
      font-size: 30px;
      font-family: Source Han Sans CN;
      font-weight: bold;
      color: #3d94ff;
      line-height: 30px;
      background: linear-gradient(-90deg, #37dc6d 0%, #34d1f9 100%);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
    }

    .upper {
      display: block !important;
      animation: masked-animation 0.5s;
      -webkit-animation: masked-animation 0.5s;
      transform: rotate(360deg);
    }

    .lower {
      animation: masked-animation 1s linear;
      -webkit-animation: masked-animation 1s linear;
      display: none !important;
    }
  }
}

.select-item {
  .selectactive {
    background: #282a2c;
    border: 1px solid #ffffff;
    color: #ffffff;
  }

  span {
    margin-top: 30px;
    padding: 22px 36px;
    display: inline-block;
    background: #282a2c;
    border-radius: 34px;
    font-size: 28px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #b9c4c7;
    line-height: 18px;
    margin-left: 20px;
  }
}
</style>